include $(MAKE_ROOT)/env.mk


MY_PATH=$(shell pwd)
MY_RELATIVE_PATH=$(subst $(MAKE_ROOT)src/,,$(MY_PATH))
# the .o absolute dir of this source dir
MY_OBJ_PATH=$(OBJ_ROOT)/$(MY_RELATIVE_PATH)/
# the .d absolute dir of this source dir
MY_DEP_PATH=$(DEP_ROOT)/$(MY_RELATIVE_PATH)/

# To realize increment building, this line is needed.
-include $(wildcard $(addsuffix /*.d,$(MY_DEP_PATH)))

SRCS:=$(wildcard *.cpp)
OBJS:=$(patsubst %.cpp,%.o,$(SRCS))
DEPS:=$(patsubst %.cpp,%.d,$(SRCS))

.PHONY:all
all:init $(DEPS) $(OBJS)

init:
	mkdir -p $(MY_OBJ_PATH)
	mkdir -p $(MY_DEP_PATH)

%.d:%.cpp
	$(CC) $(DEPFLAGS) $< -o $(MY_DEP_PATH)/$@
	
%.o:%.cpp
	$(CC) $(CCFLAGS) -c $< -o $(MY_OBJ_PATH)/$@